﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Adatkezelo.Classes;
using System.Data.SqlClient;

namespace NEMProjectWebApp.Pages.Admin {
    public partial class targykezeles : System.Web.UI.Page {
        TargyKezelo targykez;
        Login_Kezeles login = new Login_Kezeles();
        protected void Page_Load(object sender, EventArgs e) {
            string redirect = login.BelepesiJogkorEll(Session, 1);
            if (redirect.Length > 0) Response.Redirect(redirect);
            targykez = new TargyKezelo();
            //dataBind();
        }
        public void dataBind() {
            if (OktatokDropDownList.SelectedIndex > -1) {
                SqlDataSource1.SelectCommand = "SELECT Targy.* " +
                    "FROM Targy,UserTargyKapcs " +
                    "where UserTargyKapcs.Targy_ID = Targy.T_ID " +
                    "and UserTargyKapcs.User_ID = '" + OktatokDropDownList.SelectedValue + "'";
                SqlDataSource1.DataBind();
                TargyakListBox.DataBind();
            }
        }
        protected void Button1_Click(object sender, EventArgs e) {
            string kezd = (!KoraTextBox.Text.Equals("") ? KoraTextBox.Text : "0") + ":" + (!KpercTextBox.Text.Equals("") ? KpercTextBox.Text : "0");
            string veg = (!VoraTextBox.Text.Equals("") ? VoraTextBox.Text : "0") + ":" + (!VpercTextBox.Text.Equals("") ? VpercTextBox.Text : "0");
            targykez.TargyLetrehoz(OktatokDropDownList.SelectedValue, UjTargyTextBox.Text, kezd, veg, TargyLeirasTextBox.Text);
            dataBind();
        }

        protected void Button2_Click(object sender, EventArgs e) {
            targykez.TargyTorl(OktatokDropDownList.SelectedValue, TargyakListBox.SelectedValue);
            dataBind();
        }
    }
}